﻿import json
import os
from pathlib import Path

from baidu_classifier import BaiduImageClassifier, BaiduAPIError

config_path = Path("baidu_ai_config.json")
config = json.loads(config_path.read_text(encoding="utf-8"))
api_key = config["api_key"]
secret_key = config["secret_key"]
classifier = BaiduImageClassifier(
    api_key,
    secret_key,
    min_score=float(config.get("min_score", 0.6)),
    allow_unclassified=bool(config.get("allow_unclassified", True)),
)
folder = Path(r"C:\Users\Administrator\Desktop\百度识别测试图片")
files = [p for p in folder.iterdir() if p.is_file()]
print(f"Total files in folder: {len(files)}")
classification, stats = classifier.classify_files(files)
print("Classification result:")
for folder_name, names in classification.items():
    print(f"- {folder_name}: {len(names)} files -> {names}")
print("Stats:")
print(stats)
